<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

if($_RQ['op']=='list'){	
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','title','status');
	$list=pdo_getslice('jy_weishop_store',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$sale=$this->plugin_setting('storeset')['sale'];
		foreach($list as &$item){
			$item['sale']=$sale;
			$nowyue = mktime(0,0,0,date('m'),1,date('Y'));
			$yesyue = mktime(0,0,0,date('m')-1,1,date('Y'));
			$item['totle']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'storeid'=>$item['id']),'price');
			$item['tsale']=price($item['totle']*$sale/100);
			$order=pdo_getall('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'storeid'=>$item['id'],'finishtime >'=>$yesyue),array('price','finishtime'));
			$now=0;
			$yes=0;
			foreach($order as &$v){
				$yes +=	$v['price'];
				if($v['finishtime']>$nowyue){
					$now +=	$v['price'];
				}
			}
			$item['now']=price($now*$sale/100);
			$item['yes']=price($yes*$sale/100);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',		
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'tip'=>'[温馨提示]：门店设置--设置门店绩效%','edit'=>false,'list'=>array(
			array('name'=>'title','title'=>'门店','type'=>'string'),
			array('name'=>'sale','title'=>'绩效比例（%）','type'=>'string'),
			array('name'=>'totle','title'=>'总成交金额','type'=>'string'),
			array('name'=>'tsale','title'=>'总绩效','type'=>'string'),
			array('name'=>'now','title'=>'当月绩效','type'=>'string'),
			array('name'=>'yes','title'=>'上月绩效','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>15,'title'=>'门店名称','type'=>'string'),
		)
	);	
	$return['htmls']=$htmls;	
	exi($return);
}
